package com.iamsleeping;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

/**
 * Created by Mohit on 05-Apr-14.
 */
class AlarmReceiver extends BroadcastReceiver {
    Settings settings;
    
    private static final int MY_NOTIFICATION_ID=1;
    private NotificationManager notificationManager;
    private Notification myNotification;

    private final String myBlog = "http://android-er.blogspot.com/";

    public AlarmReceiver(Context context){
        settings=Settings.getInstance(context);
    }
    @Override
    public void onReceive(Context context, Intent arg1) {
        // TODO Auto-generated method stub
        Toast.makeText(context, "Wakey Wakey !!", Toast.LENGTH_LONG).show();
        settings.setAlarmOn(false); //TODO snooze option
        
        /*
        NotificationManager myNotificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.ic_launcher, "Update Device", 0);
        Intent notificationIntent = new Intent(context, SettingsActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, "Device CheckIn", "Please run Device CheckIn", contentIntent);
        notification.flags |= Notification.FLAG_HIGH_PRIORITY;
        myNotificationManager.notify(0, notification);
        
         */
        
        notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
        	   myNotification = new Notification(R.drawable.ic_launcher,"Notification!",System.currentTimeMillis());
        	   String notificationTitle = "Alarm From I m Sleeping";
        	   String notificationText = "Its time to view alarm";
        	   Intent myIntent = new Intent(context, SettingsActivity.class);
        	   PendingIntent pendingIntent = PendingIntent.getActivity(context,
        	       0, myIntent,
        	       Intent.FLAG_ACTIVITY_NEW_TASK);
        	   myNotification.defaults |= Notification.DEFAULT_SOUND;
        	   myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
        	   myNotification.setLatestEventInfo(context,
        	      notificationTitle,
        	      notificationText,
        	      pendingIntent);
        	   notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
        	   
        	  
        	  
        	  
        	   
    }

}
